package com.jhmk.jhecis.config;

import com.jhmk.jhecis.config.job.Job1;
import org.quartz.*;
import org.springframework.context.annotation.Bean;

/*
写死的定时任务
 */
//@Configuration
public class QuartzConfig {

    /*
    任务详情 jobDetail 指定job
     */
    //@Bean
    public JobDetail jobDetail() {
        return JobBuilder.newJob(Job1.class)
                .storeDurably()//启用持久化,
                .withIdentity("job1","group1")//指定名字，任务组
                .usingJobData("count",1)//数据初始化。执行次数
                .build();
    }

    /*
    创建触发器
     */
    //@Bean
    public Trigger trigger() {
        String cronExpression = "0/2 * * * * ? *";
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing();//错过的不在补偿
//        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionFireAndProceed();//错过的合并为一次执行
//        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionIgnoreMisfires();//过错的全部补偿
        return TriggerBuilder.newTrigger()
                //.startAt(DateBuilder.todayAt(21, 50, 0))//任务初次执行时间
                .forJob(jobDetail())
                .withSchedule(cronScheduleBuilder)
                .withIdentity("trigger1", "group1")//命名
                .build();
    }
}
